package com.liy.framework.common.kafka;

import com.liy.framework.common.kafka.vo.OperationLog;
import com.liy.framework.common.utils.JSONUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;



@RestController
@SpringBootApplication
public class KafkaApplication {
    @Autowired
    private MessageBox producer;

    public KafkaApplication() {
    }

    public static void main(String[] args) {
        SpringApplication.run(KafkaApplication.class, args);
    }

    @GetMapping({"/send"})
    public String send(String text) {
        OperationLog log = new OperationLog();
        log.setFunctionName("测试功能:" + text);
        log.setFunctionCode("TEST-CODE");
        log.setUserId("admin");

        try {
            this.producer.sendMsg("test-logs", JSONUtils.object2Json(log));
            return "发送成功：" + JSONUtils.object2Json(log);
        } catch (IOException var4) {
            var4.printStackTrace();
            return "==";
        }
    }

    @GetMapping({"/send1"})
    public String send1() {
        OperationLog log = new OperationLog();
        log.setFunctionName("测试功能");
        log.setFunctionCode("TEST-CODE");
        log.setUserId("admin");
        this.producer.sendMsg("test-logs", "测试消息发送成功");
        return "测试消息发送成功";
    }
}
